package com.hontech.bread.ui.view

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.drawable.Drawable
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.LinearLayout
import android.widget.TextView
import com.hontech.bread.R
import com.hontech.bread.utils.stringById


class LabelTextView(context: Context, attrs: AttributeSet) : FrameLayout(context, attrs) {

    private val tvVal: TextView
    val keyTv: TextView
    val ll: LinearLayout

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.view_label_text, this)
        val attr = context.obtainStyledAttributes(attrs, R.styleable.LabelTextView)
        val key = attr.getString(R.styleable.LabelTextView_lt_key)
        attr.recycle()

        keyTv = view.findViewById(R.id.id_tv_key)
        tvVal = view.findViewById(R.id.id_tv_val)
        ll = view.findViewById(R.id.id_ll_border)

        keyTv.text = key
    }

    fun setkeyTv(key: String) {
        keyTv.text = key
    }

    fun setback(background: Drawable) {
        ll.background = background
    }

    fun setMinWidth(width: Int, width2: Int) {
        keyTv.minWidth = width
        tvVal.minWidth = width2
    }

    fun set(text: Int) {
        tvVal.text = text.toString()
    }

    fun set(text: String) {
        tvVal.text = text
    }

    fun set(value: Double) {
        tvVal.text = String.format("%.3f", value)
    }

    fun set(value: Float) {
        tvVal.text = String.format("%.3f", value)
    }

    fun setC(value: Float) {
        tvVal.text = "${String.format("%.1f", value)}℃"
    }

    fun setC(value: Int) {
        tvVal.text = "${value}℃"
    }

    @SuppressLint("SetTextI18n")
    fun setS(value: Int) {
        tvVal.text = "${value}${stringById(R.string.t1733460848_450)}"
    }

    @SuppressLint("SetTextI18n")
    fun setMin(value: Int) {
        tvVal.text = "${value}${stringById(R.string.t1733460848_451)}"
    }

    fun setKPa(value: Int) {
        tvVal.text = "${value}kPa"
    }

}

